package edu.cuit.svsp.controller;

import edu.cuit.svsp.entity.Danmu;
import edu.cuit.svsp.request.ResponseResult;
import edu.cuit.svsp.service.DanmuService;
import edu.cuit.svsp.util.JWTUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @className: DanmuController
 * @author: pjy
 * @description: 弹幕控制器
 * @date: 2024/7/6
 */
@Slf4j
@RestController
@RequestMapping("/danmu")
public class DanmuController {
    @Resource
    private DanmuService danmuService;


    // 添加弹幕
    @PostMapping("/add")
    public ResponseResult add(@RequestBody Danmu danmu, HttpServletRequest request) {
        int uid = JWTUtil.getuid(request.getHeader("Authorization"));
        danmu.setUid(uid);
        return new ResponseResult(HttpStatus.OK.value(), "success",danmuService.add(danmu));
    }

    // 根据视频id查询弹幕
    @GetMapping("/findByVid/{vid}")
    public ResponseResult findByVid(@PathVariable("vid") Integer vid) {
        return new ResponseResult(HttpStatus.OK.value(), "success",danmuService.findByVid(vid));
    }
}
